package com.code2roc.jarmanage.servlet.project;

import com.code2roc.jarmanage.db.ProjectDB;
import com.code2roc.jarmanage.model.ProjectDO;
import com.code2roc.jarmanage.model.Result;
import com.code2roc.jarmanage.util.CommonUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Result result = Result.okResult();
        ProjectDO entity = CommonUtil.getParamEntity(req,ProjectDO.class);
        if(ProjectDB.checkExistServiceName(entity.getServiceName(),entity.getProjectID())){
            result = Result.errorResult().setMsg("服务名称重复");
            resp.getWriter().println(result.toString());
            return;
        }
        if(ProjectDB.checkExistDepolyPort(entity.getDepolyPort(),entity.getProjectID())){
            result = Result.errorResult().setMsg("部署端口重复");
            resp.getWriter().println(result.toString());
            return;
        }
        ProjectDB.update(entity);
        resp.getWriter().println(result.toString());
    }
}
